<?php
/**
 * Created by PhpStorm.
 * User: wk
 * Date: 2018/4/12
 * Time: 20:48
 */

namespace app\admin\controller;

use think\Session;
use think\Controller;
use think\request;
class Admincontroller extends Controller
{

        public function _initialize()
    {

        $res=Session::has('admin');
//        var_dump($res);die;
            if (!$res){
//            var_dump($res);die;
            $this->redirect('admin/Login/index');
        }
            $session=Request::instance()->session();
//        var_dump($session['nodelist']);die;
            $arr=array();
            foreach($session['nodelist'] as $v){
                $aname=explode(',',$v['anames']);
                foreach ($aname as $va){
                    $unode=$v['mname'].'/'.$va;
                    $arr[]=$unode;
                }
            }

            $request= Request::instance();
            $module_name=$request->module();
            $con=$request->controller();
            $act=$request->action();
//            $nodelist=$session.nodelist;
//            var_dump($nodelist);die;
            $str=$con.'/'.$act;

//            var_dump($str);die;

            if($session['admin']['username']!='admin')
            {
//                var_dump($str);
//                var_dump($arr);die;
                if(!in_array($str,$arr)){
                    $this->error('没有权限','admin/Main/index');
                }
            }
    }

}